home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH6 / SRC / CIRCLE2.FRM < prev    next >
Text File  |  1996-05-01  |  5KB  |  193 lines

  1. VERSION 4.00
  2. Begin VB.Form CircleForm 
  3.    Caption         =   "Circle 2"
  4.    ClientHeight    =   5670
  5.    ClientLeft      =   2115
  6.    ClientTop       =   945
  7.    ClientWidth     =   4830
  8.    Height          =   6360
  9.    Left            =   2055
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   378
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   322
  14.    Top             =   315
  15.    Width           =   4950
  16.    Begin VB.TextBox YscaleText 
  17.       Height          =   285
  18.       Left            =   2160
  19.       TabIndex        =   9
  20.       Text            =   "0.5"
  21.       Top             =   480
  22.       Width           =   615
  23.    End
  24.    Begin VB.TextBox XscaleText 
  25.       Height          =   285
  26.       Left            =   600
  27.       TabIndex        =   7
  28.       Text            =   "1.0"
  29.       Top             =   480
  30.       Width           =   615
  31.    End
  32.    Begin VB.TextBox DtText 
  33.       Height          =   285
  34.       Left            =   2160
  35.       TabIndex        =   6
  36.       Text            =   "0.1"
  37.       Top             =   45
  38.       Width           =   615
  39.    End
  40.    Begin VB.TextBox TminText 
  41.       Height          =   285
  42.       Left            =   0
  43.       TabIndex        =   4
  44.       Text            =   "0"
  45.       Top             =   45
  46.       Width           =   615
  47.    End
  48.    Begin VB.CommandButton CmdGo 
  49.       Caption         =   "Go"
  50.       Default         =   -1  'True
  51.       Height          =   375
  52.       Left            =   4200
  53.       TabIndex        =   3
  54.       Top             =   0
  55.       Width           =   615
  56.    End
  57.    Begin VB.TextBox TmaxText 
  58.       Height          =   285
  59.       Left            =   1200
  60.       TabIndex        =   2
  61.       Text            =   "6.2832"
  62.       Top             =   45
  63.       Width           =   615
  64.    End
  65.    Begin VB.PictureBox Canvas 
  66.       AutoRedraw      =   -1  'True
  67.       Height          =   4815
  68.       Left            =   0
  69.       ScaleHeight     =   -2.2
  70.       ScaleLeft       =   -1.1
  71.       ScaleMode       =   0  'User
  72.       ScaleTop        =   1.1
  73.       ScaleWidth      =   2.2
  74.       TabIndex        =   0
  75.       Top             =   840
  76.       Width           =   4815
  77.    End
  78.    Begin VB.Label Label1 
  79.       Caption         =   "Y scale"
  80.       Height          =   255
  81.       Index           =   3
  82.       Left            =   1560
  83.       TabIndex        =   10
  84.       Top             =   540
  85.       Width           =   615
  86.    End
  87.    Begin VB.Label Label1 
  88.       Caption         =   "X scale"
  89.       Height          =   255
  90.       Index           =   2
  91.       Left            =   0
  92.       TabIndex        =   8
  93.       Top             =   540
  94.       Width           =   615
  95.    End
  96.    Begin VB.Label Label1 
  97.       Caption         =   "dt"
  98.       Height          =   255
  99.       Index           =   1
  100.       Left            =   1920
  101.       TabIndex        =   5
  102.       Top             =   60
  103.       Width           =   255
  104.    End
  105.    Begin VB.Label Label1 
  106.       Caption         =   "<= t <="
  107.       Height          =   255
  108.       Index           =   0
  109.       Left            =   645
  110.       TabIndex        =   1
  111.       Top             =   60
  112.       Width           =   495
  113.    End
  114.    Begin VB.Menu mnuFile 
  115.       Caption         =   "&File"
  116.       Begin VB.Menu mnuFileExit 
  117.          Caption         =   "E&xit"
  118.       End
  119.    End
  120. End
  121. Attribute VB_Name = "CircleForm"
  122. Attribute VB_Creatable = False
  123. Attribute VB_Exposed = False
  124. Option Explicit
  125.  
  126. Const PI = 3.14159
  127.  
  128.  
  129. ' ************************************************
  130. ' Draw the curve on the indicated picture box.
  131. ' ************************************************
  132. Sub DrawCurve(pic As PictureBox, start_t As Single, stop_t As Single, dt As Single, xscale As Single, yscale As Single)
  133. Dim x1 As Single
  134. Dim y1 As Single
  135. Dim t As Single
  136.  
  137.     x1 = xscale * X(start_t)
  138.     y1 = yscale * Y(start_t)
  139.     pic.Cls
  140.     pic.CurrentX = x1
  141.     pic.CurrentY = y1
  142.     
  143.     t = start_t + dt
  144.     Do While t < stop_t
  145.         x1 = xscale * X(t)
  146.         y1 = yscale * Y(t)
  147.         pic.Line -(x1, y1)
  148.         t = t + dt
  149.     Loop
  150.     
  151.     x1 = xscale * X(stop_t)
  152.     y1 = yscale * Y(stop_t)
  153.     pic.Line -(x1, y1)
  154. End Sub
  155.  
  156.  
  157.  
  158. ' ************************************************
  159. ' The parametric function Y(t).
  160. ' ************************************************
  161. Function Y(t As Single) As Single
  162.     Y = Sin(t)
  163. End Function
  164.  
  165. ' ************************************************
  166. ' The parametric function X(t).
  167. ' ************************************************
  168. Function X(t As Single) As Single
  169.     X = Cos(t)
  170. End Function
  171.  
  172. Private Sub CmdGo_Click()
  173. Dim tmin As Single
  174. Dim tmax As Single
  175. Dim dt As Single
  176. Dim xscale As Single
  177. Dim yscale As Single
  178.  
  179.     tmin = CSng(TminText.Text)
  180.     tmax = CSng(TmaxText.Text)
  181.     dt = CSng(DtText.Text)
  182.     xscale = CSng(XscaleText.Text)
  183.     yscale = CSng(YscaleText.Text)
  184.     DrawCurve Canvas, tmin, tmax, dt, xscale, yscale
  185. End Sub
  186.  
  187.  
  188. Private Sub mnuFileExit_Click()
  189.     Unload Me
  190. End Sub
  191.  
  192.  
  193.